﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenNETCF.MTConnect;
using OpenNETCF.IoC;
using MachineSimulator.Interfaces;

namespace SimulatorAdapter
{
    public class MachineInterface : IMachineInterface
    {
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        private MachineDevice MachineDevice { get; set; }

        public MachineInterface(MachineDevice device)
        {
            MachineDevice = device;
        }

        public int X
        {
            get
            {
                return MachineDevice.XAxis.Xcom;
            }
            set
            {
                MachineDevice.XAxis.Xcom = value;
                MachineDevice.XAxis.Xact = value;
            }
        }

        public int Y
        {
            get
            {
                return MachineDevice.YAxis.Ycom;
            }
            set
            {
                MachineDevice.YAxis.Ycom = value;
                MachineDevice.YAxis.Yact = value;
            }
        }

        public int Z
        {
            get
            {
                return MachineDevice.ZAxis.Zcom;
            }
            set
            {
                MachineDevice.ZAxis.Zcom = value;
                MachineDevice.ZAxis.Zact = value;
            }
        }

        public int Power
        {
            get
            {
                return MachineDevice.Systems.Electric.Amp1;
            }
            set
            {
                MachineDevice.Systems.Electric.Amp1 = value;
                MachineDevice.Systems.Electric.Amp2 = value;
                MachineDevice.Systems.Electric.Amp3 = value;
            }
        }

        public bool DoorOpen
        {
            get { return MachineDevice.Door.DoorOpen; }
            set { MachineDevice.Door.DoorOpen = value; }
        }

        public bool EStop
        {
            get { return MachineDevice.Controller.EStop; }
            set { MachineDevice.Controller.EStop = value; }
        }

        public string ControllerBlock
        {
            get { return MachineDevice.Controller.Path.Block; }
            set { MachineDevice.Controller.Path.Block = value; }
        }
        
        public string ControllerMode
        {
            get { return MachineDevice.Controller.Path.Mode; }
            set { MachineDevice.Controller.Path.Mode = value;  }
        }

        public string ControllerExecution
        {
            get { return MachineDevice.Controller.Path.Execution; }
            set { MachineDevice.Controller.Path.Execution = value; }
        }

        public string ControllerProgram
        {
            get { return MachineDevice.Controller.Path.Program; }
            set { MachineDevice.Controller.Path.Program = value; }
        }

        public void AcknowlegeFaults()
        {
            MachineDevice.Systems.Electric.AcknowledgeOverCurrent();
        }
    }
}
